local klmou__huangtian_active = fk.CreateSkill({
  name = "klmou__huangtian_active&",
})

Fk:loadTranslationTable{
  ["klmou__huangtian_active&"] = "黄天",
  [":klmou__huangtian_active&"] = "出牌阶段限一次，你可将一张牌交给谋张角，或令谋张角使用一张牌。",

  ["#klmou__huangtian-active"] = "发动黄天，将一张牌交给谋张角，或直接点确定令谋张角使用一张牌",
  ["#klmou__huangtian"] = "黄天：请选择一名角色作为本次技能的“谋张角”",
  ["#klmou__huangtian-use"] = "黄天：你须使用一张牌",
}

klmou__huangtian_active:addEffect("active", {
  anim_type = "support",
  prompt = "#klmou__huangtian-active",
  mute = true,
  max_card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    if player:usedSkillTimes(klmou__huangtian_active.name, Player.HistoryPhase) < 1 and player.kingdom == "qun" then
      return table.find(Fk:currentRoom().alive_players, function(p) return p:hasSkill("klmou__huangtian") and p ~= player end)
    end
    return false
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local targets = table.filter(room.alive_players, function(p)
      return p:hasSkill("klmou__huangtian") and p ~= player
    end)
    local target
    if #targets == 1 then
      target = targets[1]
    else
      target = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = "klmou__huangtian",
        prompt = "#klmou__huangtian",
        cancelable = false,
      })[1]
    end
    if not target then return end
    if #effect.cards > 0 then
      room:notifySkillInvoked(target, "klmou__huangtian", "drawcard")
      target:broadcastSkillInvoke("klmou__huangtian")
      room:doIndicate(player, { target })
      room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, "klmou__huangtian", nil, true, player)
    else
      room:notifySkillInvoked(target, "klmou__huangtian", "control")
      target:broadcastSkillInvoke("klmou__huangtian")
      local use = room:askToUseRealCard(target, {
        pattern = ".|.|.|hand",
        skill_name = "klmou__huangtian",
        prompt = "#klmou__huangtian-use",
        cancelable = false,
        extra_data = {
          bypass_times = true,
        },
        skip = true,
      })
      if use then
        use.extraUse = true
        room:useCard(use)
      end
    end
  end,
})


return klmou__huangtian_active
